export default {
  set (key, value) {
    // let data = value
    // if (typeof value === 'object' && value) {
    //   data = JSON.stringify(value)
    // }
    localStorage.setItem(key, JSON.stringify(value))
  },
  get (key) {
    return JSON.parse(localStorage.getItem(key))
  },
  remove (key) {
    localStorage.removeItem(key)
  },
  setAccessToken (data) {
    console.log('setAccessToken', data)
    sessionStorage.setItem('accessToken', JSON.stringify(data))
  },
  // localStorage
  dispatchLocalStorageEvent () {
    const signSetItem = localStorage.setItem
    localStorage.setItem = function (key, val) {
      let setEvent = new Event('setLocalItemEvent')
      setEvent.key = key
      setEvent.newValue = val
      window.dispatchEvent(setEvent)
      signSetItem.apply(this, arguments)
    }
  },
  // sessionStorage
  dispatchSessionStorageEvent () {
    const signSetItem = sessionStorage.setItem
    sessionStorage.setItem = function (key, val) {
      let setEvent = new Event('setSessionItemEvent')
      setEvent.key = key
      setEvent.newValue = val
      window.dispatchEvent(setEvent)
      signSetItem.apply(this, arguments)
    }
  }
}
